<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>限额投放设置表 管理</title>
    <style type="text/css">
    </style>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">类型</div>
                    <div class="field">
                        <input name="cfgTypCd" id="cfgTypCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">机构名称</div>
                    <div class="field">
                        <input name="mgtOrgNm" id="mgtOrgNm" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox">
                    <div class="label">状态</div>
                    <div class="field">
                        <input name="limStsCd" id="limStsCd" data-value="" placeholder="请选择" ltype="combobox">
                    </div>
                </div>

                <div class="formBtns notRight">
                    <span id="searchBtn" class="sq-button sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button sq-button-round">新增</span>
                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
    <div id="ligergrid1" class="sq-grid"></div>
</div>

<script type="text/javascript">
    var grid = null, callback = null;
    $(function () {
        grid = $("#ligergrid1").ligerGrid({
            url: '<%=path%>/capital/capPayLimCfg/initList.do',
            method: 'get',
            columns: [
                {display: '类型', name: 'cfgTypCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '机构名称', name: 'mgtOrgNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '生效时间', name: 'startTm', minWidth: 100, align: 'center', enabledSort: false,render:renderDate},
                {display: '启用额度(元)', name: 'ttlAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.ttlAmt / 100);
                    }
                },
                {display: '剩余额度(元)', name: 'restAmt', minWidth: 100, align: 'right', enabledSort: false,
                    render: function (rowdata, index, value) {
                        return '&yen;' + FormatMoney(rowdata.restAmt / 100);
                    }
                },
                {display: '状态', name: 'limStsCdNm', minWidth: 100, align: 'left', enabledSort: false},
                {display: '取消时间', name: 'endTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '添加时间', name: 'crtTm', minWidth: 100, align: 'left', enabledSort: false,render:renderDate},
                {display: '操作', name: '', minWidth: 100, align: 'left', enabledSort: false,
                    render: function (rowdata, index, value) {
                        if (rowdata.limStsCd==1) {
                            return "<a class='sq-button-hasicon' href='javascript:;' onclick='cancelLimit(" + rowdata.id+","+ rowdata.mgtOrgId+ ")'><i class='sqBtnIco_17'></i>取消限额</a>";
                        }
                    }
                },
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: true,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false
        });
        grid.setHeight(100);

        $("#cfgTypCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });

        $("#limStsCd").ligerComboBox({
            valueField: 'key',
            textField: 'value',
        });

        $("#searchBar").ligerForm();
        liger.get("cfgTypCd").setData(${cfgTypCdList});
        liger.get("limStsCd").setData(${limStsCdList});

        $("#pageloading").hide();

        /* 查询 */
        $("#searchBtn").click(function (event) {
            var form = liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload();
        });

        /* 清空 */
        $("#clearBtn").click(function (event) {
            clearLigerForm("searchBar");
        });

        callback = function () {
            grid.reload();
        };

        /* 新增 */
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 850,
                height: 470,
                title: '新增限额投放设置',
                url: '<%=path%>/capital/capPayLimCfg/toAddPage.do'
            });
        });
    });

    //取消限额
    function cancelLimit(id,mgtOrgId){
        $.ligerDialog.confirm("取消限额后，系统中等待放款的数据将会自动发送至资金系统,确认取消限额？", function (flag) {
            if (flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                url: '<%=path%>/capital/capPayLimCfg/modify.do?id='+id+'&limStsCd=0&mgtOrgId='+mgtOrgId,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        $("#clearBtn").click();
                        $("#searchBtn").click();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, "yyyy-MM-dd hh:mm");
        }
        return dateStr;
    }

</script>

</body>
</html>
